import $axios from "@/network";

/**
 * {权限管理添加，编辑共用参数}
 *
 * @author: 宋康
 * @date: 2022/8/18 14:29
 */
export const meunPublic = {
  data() {
    return {
      form: {
        meunName: '',
        meunType: '1',
        level: '1',
        parentId: '',
        purview: [],
      },
      rules: {
        meunName: [
          {required: true, message: '请输入许可名称', trigger: 'blur'},
          {min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur'}
        ],
        meunType: [
          {required: true, message: '请选择许可类型', trigger: 'change'}
        ],
        level: [
          {required: true, message: '请选择许可等级', trigger: 'change'}
        ],
      },
    }
  },
  methods: {
    /**
     * {返回}
     *
     * @author: 宋康
     * @date: 2022/8/18 14:48
     */
    cancel() {
      this.$router.go(-1)
    }
  }
}


/**
 * {获取菜单列表}
 * @param keyword
 * @param isParent
 * @param excludes
 * @author: 宋康
 * @date: 2022/8/18 09:43
 */
export const meunList = (keyword, isParent, excludes) => {
  return $axios({
    method: 'POST',
    url: '/meun/query/list',
    data: {
      keyword,
      isParent,
      excludes
    }
  })
}
/**
 * {获取权限列表}
 *
 * @author: 宋康
 * @date: 2022/8/18 10:20
 */
export const purviewList = () => {
  return $axios({
    url: '/purview/query/list'
  })
}

/**
 * {保存菜单}
 * @param option
 * @author: 宋康
 * @date: 2022/8/18 14:45
 */
export const saveMeun = (option) => {
  return $axios({
    method: 'POST',
    url: '/meun/save',
    data: {
      ...option
    }
  })
}
/**
 * {编辑菜单}
 * @param option
 * @author: 宋康
 * @date: 2022/8/18 16:23
 */
export const editMeun = (option) => {
  return $axios({
    method: 'POST',
    url: '/meun/edit',
    data: {
      ...option
    }
  })
}

/**
 * {移除指定菜单}
 * @param mid
 * @author: 宋康
 * @date: 2022/8/18 17:43
 */
export const removeMeun = (mid) => {
  return $axios({
    method: 'POST',
    url: '/meun/remove',
    params: {
      mid
    }
  })
}

/**
 * {获取指定菜单}
 * @param mid
 * @author: 宋康
 * @date: 2022/8/18 15:46
 */
export const queryMeunByMid = (id) => {
  return $axios({
    url: '/meun/query',
    params: {
      id
    }
  })
}